﻿Imports System.Data.SqlClient
Public Class clsNominasIngreso
    Private mintIdIngreso As Integer
    Private mdatFecha As Date
    Private mdblIngreso As Double
    Private mintStatus As Integer
    Public Property IdIngreso() As Integer
        Get
            Return mintIdIngreso
        End Get
        Set(ByVal value As Integer)
            mintIdIngreso = value
        End Set
    End Property
    Public Property Fecha As Date
        Get
            Return mdatFecha
        End Get
        Set(ByVal value As Date)
            mdatFecha = value
        End Set
    End Property
    Public Property Ingreso() As Double
        Get
            Return mdblIngreso
        End Get
        Set(ByVal value As Double)
            mdblIngreso = value
        End Set
    End Property
    Public Property Status() As Integer
        Get
            Return mintStatus
        End Get
        Set(ByVal value As Integer)
            mintStatus = value
        End Set
    End Property

    Public Sub New()
        mintIdIngreso = 0
        mdatFecha = Now()
        mdblIngreso = 0
        mintStatus = 0
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into NominasIngreso (" & _
                            "Fecha," & _
                            "Ingreso," & _
                            "Status)" & _
                            "VALUES (" & _
                            "@Fecha," & _
                            "@Ingreso," & _
                            "@Status)" & _
                            " SELECT SCOPE_IDENTITY()"


        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("Fecha", mdatFecha)
        Command.Parameters.AddWithValue("Ingreso", mdblIngreso)
        Command.Parameters.AddWithValue("Status", mintStatus)

        cnConn.Open()
        IdIngreso = Convert.ToInt32(Command.ExecuteScalar)

        If IdIngreso > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el registro ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub

End Class
